﻿//using System;
//using System.Diagnostics;
//using System.IO;
//using System.Xml;
//using System.Xml.XPath;

//namespace PerformanceCounters
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
//                        <people>
//                        <person firstname=""john"" lastname=""doe"">
//                        <contactdetails>
//                        <emailaddress>john@unknown.com</emailaddress>
//                        </contactdetails>
//                        </person>
//                        <person firstname=""jane"" lastname=""doe"">
//                        <contactdetails>
//                        <emailaddress>jane@unknown.com</emailaddress>
//                        <phonenumber>001122334455</phonenumber>
//                        </contactdetails>
//                        </person>
//                        </people>";

//            XmlDocument doc = new XmlDocument();
//            doc.LoadXml(xml);
//            XmlNodeList nodes = doc.GetElementsByTagName("Person");
//            // Output the names of the people in the document
//            foreach (XmlNode node in nodes)
//            {
//                string firstName = node.Attributes["firstName"].Value;
//                string lastName = node.Attributes["lastName"].Value;
//                Console.WriteLine("Name: {0} {1}", firstName, lastName);
//            }
//            // Start creating a new node
//            XmlNode newNode = doc.CreateNode(XmlNodeType.Element, "Person", "");
//            XmlAttribute firstNameAttribute = doc.CreateAttribute("firstName");
//            firstNameAttribute.Value = "Foo";
//            XmlAttribute lastNameAttribute = doc.CreateAttribute("lastName");
//            lastNameAttribute.Value = "Bar";
//            newNode.Attributes.Append(firstNameAttribute);
//            newNode.Attributes.Append(lastNameAttribute);
//            doc.DocumentElement.AppendChild(newNode);
//            Console.WriteLine("Modified xml...");
//            doc.Save(Console.Out);
//            Console.ReadKey();
//            Console.WriteLine();

//            XmlDocument doc2 = new XmlDocument();
//            doc.LoadXml(xml); // Can be found in Listing 4-43

//            XPathNavigator nav = doc2.CreateNavigator();
//            string query = "//People/Person[@firstName='jane']";
//            XPathNodeIterator iterator = nav.Select(query);
//            Console.WriteLine(iterator.Count); // Displays 1
//            while (iterator.MoveNext())
//            {
//                string firstName = iterator.Current.GetAttribute("firstName", "");
//                string lastName = iterator.Current.GetAttribute("lastName", "");
//                Console.WriteLine("Name: {0} {1}", firstName, lastName);
//            }
//            Console.ReadKey();
//        }
//    }
//}